Option Strict Off
Option Explicit On
Module LoadSettings
	'This modules first subroutine loads the user variables into the program from the Settings_User.txt file
	'The second subroutine saves the variables out to the file when the main program closes.
	
	
	Public Sub LoadSettingData() 'Loads in system variables and Initial form positions etc,
		Dim FileSettings As String
		Dim DataType As String
		Dim RecievedData As String
		FileSettings = My.Application.Info.DirectoryPath & "\Settings_User.txt"
		
		FileOpen(1, FileSettings, OpenMode.Input)
		Do Until (EOF(1) = True)
			
			Input(1, DataType)
			
			If UCase(DataType) = "ERRORLOGGINGYESNO" Then 'Look for what text the line begins with
				Input(1, RecievedData) 'Get Data
				If RecievedData = "True" Then
					ErrorLoggingYesNO = True
				Else
					ErrorLoggingYesNO = False
				End If
			End If
			
			If UCase(DataType) = "LASTCAMERA" Then 'Look for what text the line begins with
				Input(1, LastCamera) 'Directly load the value into the program variable
			End If
			If UCase(DataType) = "WORKDIRECTORY" Then 'Look for what text the line begins with
				Input(1, SavePath) 'Directly load the value into the program variable
				If SavePath = "NONE%%%%$" Then 'No directory set so set it to the default
					SavePath = My.Application.Info.DirectoryPath & "\Captured_Frames\" 'Set the default path to where animations are saved.
				End If
			End If
			If UCase(DataType) = "XSHEET" Then 'Look for what text the line begins with
				Input(1, XSheetName) 'Directly load the value into the program variable
			End If
			If UCase(DataType) = "SOUNDTRACK" Then 'Look for what text the line begins with
				Input(1, SoundTrackName) 'Directly load the value into the program variable
			End If
			If UCase(DataType) = "SOUNDTRACKONOFF" Then 'Look for what text the line begins with
				Input(1, RecievedData) 'Get Data
				If RecievedData = "True" Then
					SoundTrackOnOff = True
				Else
					SoundTrackOnOff = False
				End If
			End If
			If UCase(DataType) = "XSHEETOFFSET" Then 'Look for what text the line begins with
				Input(1, XSheetOffset) 'Directly load the value into the program variable
			End If
			If UCase(DataType) = "SKIN" Then 'Look for what text the line begins with
				Input(1, Skin) 'Directly load the value into the program variable
			End If
			If UCase(DataType) = "CAPTURESOUND" Then 'Look for what text the line begins with
				Input(1, CaptureSound) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "ONIONLEVEL" Then 'Look for what text the line begins with
				Input(1, OnionLevel) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "LOOPLENGTH" Then 'Look for what text the line begins with
				Input(1, LoopLength) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "CAPTUREQUALITY" Then 'Look for what text the line begins with
				Input(1, CaptureQuality) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "FRAMEAVGDEPTH" Then 'Look for what text the line begins with
				Input(1, FrameAvgDepth) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "FRAMEAVGDELAY" Then 'Look for what text the line begins with
				Input(1, FrameAvgDelay) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "FPS" Then 'Look for what text the line begins with
				Input(1, FPS) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "SAFEAREAONOFF" Then 'Look for what text the line begins with
				Input(1, RecievedData) 'Get Data
				If RecievedData = "True" Then
					SafeAreaYesNo = True
				Else
					SafeAreaYesNo = False
				End If
			End If
			
			If UCase(DataType) = "SAFEAREAWIDTH" Then 'Look for what text the line begins with
				Input(1, SafeAreaWidth) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "SAFEAREAHEIGHT" Then 'Look for what text the line begins with
				Input(1, SafeAreaHeight) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "SAFEAREACOLOUR" Then 'Look for what text the line begins with
				Input(1, SafeAreaColour) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "TIMELAPSEDELAY" Then 'Look for what text the line begins with
				Input(1, TimeLapseDelay) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "SOUNDSONOFF" Then 'Look for what text the line begins with
				Input(1, RecievedData) 'Get Data
				If RecievedData = "True" Then
					SoundsOnOff = True
				Else
					SoundsOnOff = False
				End If
			End If
			If UCase(DataType) = "MOUTHSHAPEONOFF" Then 'Look for what text the line begins with
				Input(1, RecievedData) 'Get Data
				If RecievedData = "True" Then
					MouthShapeOnOff = True
				Else
					MouthShapeOnOff = False
				End If
			End If
			If UCase(DataType) = "INDIVIDUALBMPFRAMES" Then 'Look for what text the line begins with
				Input(1, RecievedData) 'Get Data
				If RecievedData = "True" Then
					OutputBmpFramesYesNo = True
				Else
					OutputBmpFramesYesNo = False
				End If
			End If
			
			If UCase(DataType) = "INDIVIDUALJPGFRAMES" Then 'Look for what text the line begins with
				Input(1, RecievedData) 'Get Data
				If RecievedData = "True" Then
					OutputJpgFramesYesNo = True
				Else
					OutputJpgFramesYesNo = False
				End If
			End If
			
			If UCase(DataType) = "INDIVIDUALTIFFRAMES" Then 'Look for what text the line begins with
				Input(1, RecievedData) 'Get Data
				If RecievedData = "True" Then
					OutputTifFramesYesNo = True
				Else
					OutputTifFramesYesNo = False
				End If
			End If
			
			If UCase(DataType) = "INDIVIDUALGIFFRAMES" Then 'Look for what text the line begins with
				Input(1, RecievedData) 'Get Data
				If RecievedData = "True" Then
					OutputGifFramesYesNo = True
				Else
					OutputGifFramesYesNo = False
				End If
			End If
			
			If UCase(DataType) = "INDIVIDUALPNGFRAMES" Then 'Look for what text the line begins with
				Input(1, RecievedData) 'Get Data
				If RecievedData = "True" Then
					OutputPngFramesYesNo = True
				Else
					OutputPngFramesYesNo = False
				End If
			End If
			
			If UCase(DataType) = "CHROMAKEYINGYESNO" Then 'Look for what text the line begins with
				Input(1, RecievedData) 'Get Data
				If RecievedData = "True" Then
					ChromaKeyingYesNO = True
				Else
					ChromaKeyingYesNO = False
				End If
			End If
			
			If UCase(DataType) = "CHROMATYPE" Then 'Look for what text the line begins with
				Input(1, ChromaType) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "CHROMABACKGROUND" Then 'Look for what text the line begins with
				Input(1, ChromaBackground) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "THREASHOLD" Then 'Look for what text the line begins with
				Input(1, Threashold) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "FEATHER" Then 'Look for what text the line begins with
				Input(1, Feather) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "WHITELIMIT" Then 'Look for what text the line begins with
				Input(1, WhiteLimit) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "BLACKLIMIT" Then 'Look for what text the line begins with
				Input(1, BlackLimit) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "FRAMENUMBERSTAMP" Then 'Look for what text the line begins with
				Input(1, RecievedData) 'Get Data
				If RecievedData = "True" Then
					FrameNumberStampYesNo = True
				Else
					FrameNumberStampYesNo = False
				End If
			End If
			
			
			'Load in the initial form positions. These are percentage values of the total screen size and width etc.
			If UCase(DataType) = "JPEGQUALITY" Then 'Look for what text the line begins with
				Input(1, JpegQuality) 'Directly load the value into the program variable
			End If
			
			
			If UCase(DataType) = "NUMFRAMESPERCLICK" Then 'Look for what text the line begins with
				Input(1, NumFramesPerClick) 'Directly load the value into the program variable
			End If
			
			'Load in the initial form positions. These are percentage values of the total screen size and width etc.
			If UCase(DataType) = "FORMANIMATORTOP" Then 'Look for what text the line begins with
				Input(1, FormAnimatorTop) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "FORMANIMATORLEFT" Then 'Look for what text the line begins with
				Input(1, FormAnimatorLeft) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "FORMCAPTUREWIDTH" Then 'Look for what text the line begins with
				Input(1, FormCaptureWidth) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "FORMCAPTURETOP" Then 'Look for what text the line begins with
				Input(1, FormCaptureTop) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "FORMCAPTURELEFT" Then 'Look for what text the line begins with
				Input(1, FormCaptureLeft) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "CAPTURE1" Then 'Look for what text the line begins with
				Input(1, Ascii01) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "CAPTURE2" Then 'Look for what text the line begins with
				Input(1, Ascii02) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "TOSTART" Then 'Look for what text the line begins with
				Input(1, Ascii03) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "BACK1" Then 'Look for what text the line begins with
				Input(1, Ascii04) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "STOP" Then 'Look for what text the line begins with
				Input(1, Ascii05) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "PLAY" Then 'Look for what text the line begins with
				Input(1, Ascii06) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "FORWARD1" Then 'Look for what text the line begins with
				Input(1, Ascii07) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "TOEND" Then 'Look for what text the line begins with
				Input(1, Ascii08) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "LOOP" Then 'Look for what text the line begins with
				Input(1, Ascii09) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "EXIT" Then 'Look for what text the line begins with
				Input(1, Ascii10) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "TOGGLE" Then 'Look for what text the line begins with
				Input(1, Ascii11) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "TIMELAPSE" Then 'Look for what text the line begins with
				Input(1, Ascii12) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "ONION" Then 'Look for what text the line begins with
				Input(1, Ascii13) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "SETTINGS" Then 'Look for what text the line begins with
				Input(1, Ascii14) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "UTILITIES" Then 'Look for what text the line begins with
				Input(1, Ascii15) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "EDITOR" Then 'Look for what text the line begins with
				Input(1, Ascii16) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "ROTOSCOPE" Then 'Look for what text the line begins with
				Input(1, Ascii17) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "UNDO" Then 'Look for what text the line begins with
				Input(1, Ascii18) 'Directly load the value into the program variable
			End If
			
			If UCase(DataType) = "SHUTTERMACRO" Then 'Look for what text the line begins with
				Input(1, RecievedData) 'Get Data
				If RecievedData = "True" Then
					ShutterMacroYesNo = True
				Else
					ShutterMacroYesNo = False
				End If
			End If
			
			If UCase(DataType) = "MACRONAME" Then 'Look for what text the line begins with
				Input(1, MacroFilename) 'Directly load the value into the program variable
			End If
		Loop  'Close all open files
		FileClose()
		
	End Sub
	Public Sub WriteSettingData() 'write the user data out to the file
		Dim FileSettings As String
		Dim DataType As String
		FileSettings = My.Application.Info.DirectoryPath & "\Settings_User.txt"
		
		
		Call GenerateSettingsData() 'Generate the text to be output to the file
		
		FileOpen(1, FileSettings, OpenMode.Output) 'Open the file
		PrintLine(1, TextBody) 'Write out the text data
		FileClose(1) 'Close the file
		TextBody = "" 'Clear the strimg
	End Sub
	
	Public Sub GenerateSettingsData() 'Generates setting data string for saving and sending in the email error reporting program
		TextBody = "" 'Clear the string
		
		'Construct the body of the text to send
		TextBody = TextBody & "** This is the User settings for the program, window sizes, frame averaging settings etc." & Chr(13) & Chr(10)
		TextBody = TextBody & " " & Chr(13) & Chr(10)
		If ErrorLoggingYesNO = True Then
			TextBody = TextBody & "ERRORLOGGINGYESNO,True" & Chr(13) & Chr(10)
		Else
			TextBody = TextBody & "ERRORLOGGINGYESNO,False" & Chr(13) & Chr(10)
		End If
		TextBody = TextBody & "LASTCAMERA,""" & LastCamera & """" & Chr(13) & Chr(10)
		TextBody = TextBody & "WORKDIRECTORY,""" & SavePath & """" & Chr(13) & Chr(10)
		TextBody = TextBody & "XSHEET,""" & XSheetName & """" & Chr(13) & Chr(10)
		TextBody = TextBody & "SOUNDTRACK,""" & SoundTrackName & """" & Chr(13) & Chr(10)
		If SoundTrackOnOff = True Then
			TextBody = TextBody & "SOUNDTRACKONOFF,True" & Chr(13) & Chr(10)
		Else
			TextBody = TextBody & "SOUNDTRACKONOFF,False" & Chr(13) & Chr(10)
		End If
		TextBody = TextBody & "XSHEETOFFSET," & XSheetOffset & Chr(13) & Chr(10)
		TextBody = TextBody & " " & Chr(13) & Chr(10)
		TextBody = TextBody & "SKIN,""" & Skin & """" & Chr(13) & Chr(10)
		TextBody = TextBody & "CAPTURESOUND,""" & CaptureSound & """" & Chr(13) & Chr(10)
		TextBody = TextBody & " " & Chr(13) & Chr(10)
		TextBody = TextBody & "ONIONLEVEL," & OnionLevel & Chr(13) & Chr(10)
		TextBody = TextBody & "LOOPLENGTH," & LoopLength & Chr(13) & Chr(10)
		TextBody = TextBody & "CAPTUREQUALITY," & CaptureQuality & Chr(13) & Chr(10)
		TextBody = TextBody & "FRAMEAVGDEPTH," & FrameAvgDepth & Chr(13) & Chr(10)
		TextBody = TextBody & "FRAMEAVGDELAY," & FrameAvgDelay & Chr(13) & Chr(10)
		TextBody = TextBody & "FPS," & FPS & Chr(13) & Chr(10)
		If SafeAreaYesNo = True Then
			TextBody = TextBody & "SAFEAREAONOFF,True" & Chr(13) & Chr(10)
		Else
			TextBody = TextBody & "SAFEAREAONOFF,False" & Chr(13) & Chr(10)
		End If
		TextBody = TextBody & "SAFEAREAWIDTH," & SafeAreaWidth & Chr(13) & Chr(10)
		TextBody = TextBody & "SAFEAREAHEIGHT," & SafeAreaHeight & Chr(13) & Chr(10)
		TextBody = TextBody & "SAFEAREACOLOUR," & SafeAreaColour & Chr(13) & Chr(10)
		TextBody = TextBody & "TIMELAPSEDELAY," & TimeLapseDelay & Chr(13) & Chr(10)
		TextBody = TextBody & " " & Chr(13) & Chr(10)
		If SoundsOnOff = True Then
			TextBody = TextBody & "SOUNDSONOFF,True" & Chr(13) & Chr(10)
		Else
			TextBody = TextBody & "SOUNDSONOFF,False" & Chr(13) & Chr(10)
		End If
		If MouthShapeOnOff = True Then
			TextBody = TextBody & "MOUTHSHAPEONOFF,True" & Chr(13) & Chr(10)
		Else
			TextBody = TextBody & "MOUTHSHAPEONOFF,False" & Chr(13) & Chr(10)
		End If
		If OutputBmpFramesYesNo = True Then
			TextBody = TextBody & "INDIVIDUALBMPFRAMES,True" & Chr(13) & Chr(10)
		Else
			TextBody = TextBody & "INDIVIDUALBMPFRAMES,False" & Chr(13) & Chr(10)
		End If
		
		If OutputJpgFramesYesNo = True Then
			TextBody = TextBody & "INDIVIDUALJPGFRAMES,True" & Chr(13) & Chr(10)
		Else
			TextBody = TextBody & "INDIVIDUALJPGFRAMES,False" & Chr(13) & Chr(10)
		End If
		
		If OutputTifFramesYesNo = True Then
			TextBody = TextBody & "INDIVIDUALTIFFRAMES,True" & Chr(13) & Chr(10)
		Else
			TextBody = TextBody & "INDIVIDUALTIFFRAMES,False" & Chr(13) & Chr(10)
		End If
		
		If OutputGifFramesYesNo = True Then
			TextBody = TextBody & "INDIVIDUALGIFFRAMES,True" & Chr(13) & Chr(10)
		Else
			TextBody = TextBody & "INDIVIDUALGIFFRAMES,False" & Chr(13) & Chr(10)
		End If
		
		If OutputPngFramesYesNo = True Then
			TextBody = TextBody & "INDIVIDUALPNGFRAMES,True" & Chr(13) & Chr(10)
		Else
			TextBody = TextBody & "INDIVIDUALPNGFRAMES,False" & Chr(13) & Chr(10)
		End If
		
		If ChromaKeyingYesNO = True Then
			TextBody = TextBody & "CHROMAKEYINGYESNO,True" & Chr(13) & Chr(10)
		Else
			TextBody = TextBody & "CHROMAKEYINGYESNO,False" & Chr(13) & Chr(10)
		End If
		
		TextBody = TextBody & "CHROMATYPE,""" & ChromaType & """" & Chr(13) & Chr(10)
		TextBody = TextBody & "CHROMABACKGROUND,""" & ChromaBackground & """" & Chr(13) & Chr(10)
		TextBody = TextBody & "THREASHOLD," & Threashold & Chr(13) & Chr(10)
		TextBody = TextBody & "FEATHER," & Feather & Chr(13) & Chr(10)
		TextBody = TextBody & "WHITELIMIT," & WhiteLimit & Chr(13) & Chr(10)
		TextBody = TextBody & "BLACKLIMIT," & BlackLimit & Chr(13) & Chr(10)
		
		If FrameNumberStampYesNo = True Then
			TextBody = TextBody & "FRAMENUMBERSTAMP,True" & Chr(13) & Chr(10)
		Else
			TextBody = TextBody & "FRAMENUMBERSTAMP,False" & Chr(13) & Chr(10)
		End If
		
		TextBody = TextBody & "JPEGQUALITY," & JpegQuality & Chr(13) & Chr(10)
		TextBody = TextBody & "NUMFRAMESPERCLICK," & NumFramesPerClick & Chr(13) & Chr(10)
		TextBody = TextBody & " " & Chr(13) & Chr(10)
		TextBody = TextBody & "**Values below are as a percentage of screen width / screen height" & Chr(13) & Chr(10)
		TextBody = TextBody & " " & Chr(13) & Chr(10)
		TextBody = TextBody & "FORMANIMATORLEFT," & FormAnimatorLeft & Chr(13) & Chr(10)
		TextBody = TextBody & "FORMANIMATORTOP," & FormAnimatorTop & Chr(13) & Chr(10)
		TextBody = TextBody & " " & Chr(13) & Chr(10)
		TextBody = TextBody & "FORMCAPTUREWIDTH," & FormCaptureWidth & Chr(13) & Chr(10)
		TextBody = TextBody & "FORMCAPTURETOP," & FormCaptureTop & Chr(13) & Chr(10)
		TextBody = TextBody & "FORMCAPTURELEFT," & FormCaptureLeft & Chr(13) & Chr(10)
		TextBody = TextBody & " " & Chr(13) & Chr(10)
		TextBody = TextBody & "**Values below are Hotkey Ascii codes" & Chr(13) & Chr(10)
		TextBody = TextBody & " " & Chr(13) & Chr(10)
		TextBody = TextBody & "CAPTURE1," & Ascii01 & Chr(13) & Chr(10)
		TextBody = TextBody & "CAPTURE2," & Ascii02 & Chr(13) & Chr(10)
		TextBody = TextBody & "TOSTART," & Ascii03 & Chr(13) & Chr(10)
		TextBody = TextBody & "BACK1," & Ascii04 & Chr(13) & Chr(10)
		TextBody = TextBody & "STOP," & Ascii05 & Chr(13) & Chr(10)
		TextBody = TextBody & "PLAY," & Ascii06 & Chr(13) & Chr(10)
		TextBody = TextBody & "FORWARD1," & Ascii07 & Chr(13) & Chr(10)
		TextBody = TextBody & "TOEND," & Ascii08 & Chr(13) & Chr(10)
		TextBody = TextBody & "LOOP," & Ascii09 & Chr(13) & Chr(10)
		TextBody = TextBody & "EXIT," & Ascii10 & Chr(13) & Chr(10)
		TextBody = TextBody & "TOGGLE," & Ascii11 & Chr(13) & Chr(10)
		TextBody = TextBody & "TIMELAPSE," & Ascii12 & Chr(13) & Chr(10)
		TextBody = TextBody & "ONION," & Ascii13 & Chr(13) & Chr(10)
		TextBody = TextBody & "SETTINGS," & Ascii14 & Chr(13) & Chr(10)
		TextBody = TextBody & "UTILITIES," & Ascii15 & Chr(13) & Chr(10)
		TextBody = TextBody & "EDITOR," & Ascii16 & Chr(13) & Chr(10)
		TextBody = TextBody & "ROTOSCOPE," & Ascii17 & Chr(13) & Chr(10)
		TextBody = TextBody & "UNDO," & Ascii18 & Chr(13) & Chr(10)
		TextBody = TextBody & " " & Chr(13) & Chr(10)
		TextBody = TextBody & "SHUTTERMACRO," & ShutterMacroYesNo & Chr(13) & Chr(10)
		TextBody = TextBody & "MACRONAME,""" & MacroFilename & """" & Chr(13) & Chr(10)
		
	End Sub
End Module